import amaret.freestyle.board.Led0;
import amaret.freestyle.mcu.atmega.BusyWait;

module Board inherits embios.interfaces.IBoard { }

implementation {
    
    native {

        extern void xdc_runtime_System_rtsExit__I();
        
        void abort(void) __attribute__ ((externally_visible));
        int atexit(void (*fxn)(void)) __attribute__ ((externally_visible));
        void exit(int) __attribute__ ((externally_visible)) __attribute__ ((noreturn));
        
        void abort(void)
        {
           for (;;);   /* spin forever */
        }
        
        int atexit(void (*fxn)(void))
        {
            return (0);
        }
        
        void exit (int status)
        {
            xdc_runtime_System_rtsExit__I();
            abort();
        }
    }

    /*
     *  ======== startup ========
     */
    function startup()
    {
        for (var Int i = 0; i < 4; i++) {
            BusyWait.wait(100);
            Led0.toggle();
        }
    }

    /*
     *  ======== shutdown ========
     */
    function shutdown( stat )
    {

    }
  
}
